var app = angular.module('dictionaryApp', []);



app.controller('dictionaryController', function($scope, $http,DictionaryService) {
	$scope.load=function(){
		$scope.sel=$scope.sel?$scope.sel:{};
		$scope.sel.id=getQueryString("id");
		DictionaryService.list($scope.sel).success(function (response) {
			$scope.dicList=response.data;
	    });
	}
	$scope.load();
	$scope=pagination.init($scope);
	$scope.refreshData=function(){
		$scope.load();
	}

	
	$scope.dicCreator=function(){
	   	//document.location.href='manage/dictionary/addDic.jsp?id='+$scope.sel.id;
	   	redirectUrl("manage/dictionary/","addDic.jsp?id="+$scope.sel.id);
   }
   
   $scope.editTip=function(id){
	   	//document.location.href='manage/dictionary/editDic.jsp?id='+id+"&pid="+$scope.sel.id;
	   	redirectUrl("manage/dictionary/","editDic.jsp?id="+id+"&pid="+$scope.sel.id);
	   }
   
   $scope.lock=function(id){
   	DictionaryService.lock(id).success(function (response) {
   		$scope.load();
   	});
   }
  
   $scope.lockByPid=function(id){
	   DictionaryService.lockByPid(id).success(function (response) {
		   $scope.load();
	   });
   }
   
   
   $scope.delTip=function(id,mes){
   	$scope.delItem={id:id,mes:mes};
   	$('#box-del').modal({
   		show: true
   	});
   	
   }
   $scope.del=function(id){
   	DictionaryService.del(id).success(function (response) {
   		$('#box-del').modal('hide');
   		$scope.load();
   	});
   }
});


app.factory('DictionaryService', function ($http) {
	var list = function (param) {
        return $http({
           // url: 'sys/dic/getByPid/'+param.id
            url: timestamp('sys/dic/getByPid/'+param.id)
        });
    };
    var lock = function (id){
    	return $http.put('sys/dic/get/'+id);
    }
    var lockByPid = function (id) {
    	return $http.put('sys/dic/upStatusById/'+id);
    }
    var del = function (id){
    	return $http.put('sys/dic/upStatus/'+id);
    }
	return {
		list:function(param){
			return list(param);
		},
		lock:function(id){
			return lock(id);
		},
		lockByPid:function(id){
			return lockByPid(id);
		},
		del:function(id){
			return del(id);
		}
	}
});
